package com.pipe.connector;

import com.pipe.connector.nettyhandler.BasePackageDecoder;

/**
 * @author Kiven
 */
public class MysqlConnector {
    private String ip;
    private int port;

    private String mysqlUserName;
    private String mysqlPassword;

    private RowDataListener listener;

    public MysqlConnector(String ip, int port, String mysqlUserName, String mysqlPassword) {
        this.ip = ip;
        this.port = port;
        this.mysqlUserName = mysqlUserName;
        this.mysqlPassword = mysqlPassword;
    }

    public void addNewRowDataListener(RowDataListener listener){
        this.listener = listener;
    }

    public void startBinlogDumpTask(String databaseName, int binlogPos, String binlogFile){
        NettyClient client = new NettyClient(new BasePackageDecoder(databaseName, mysqlUserName, mysqlPassword, binlogPos, binlogFile, this.listener));
        client.connect(ip, port);
    }
}